package com.yiwei.zhh.activity;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.yiwei.zhh.R;
import com.yiwei.zhh.fragment.MyPrizeFragment;
import com.yiwei.zhh.view.HomeViewPager;
import com.yiwei.zhh.view.V19FrameLayout;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;

/**
 * Created by Administrator on 2018/6/10.
 */

public class MyPrizeActivity extends BaseActivity {
    @BindView(R.id.btn_back)
    ImageView btnBack;
    @BindView(R.id.txt_title)
    TextView txtTitle;
    @BindView(R.id.txt_right)
    TextView txtRight;
    @BindView(R.id.layout_title)
    V19FrameLayout layoutTitle;
    @BindView(R.id.btn_one)
    TextView btnOne;
    @BindView(R.id.line_one)
    View lineOne;
    @BindView(R.id.btn_two)
    TextView btnTwo;
    @BindView(R.id.line_two)
    View lineTwo;
    @BindView(R.id.btn_three)
    TextView btnThree;
    @BindView(R.id.line_three)
    View lineThree;
    @BindView(R.id.pager)
    HomeViewPager pager;
    private Unbinder unbinder;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my_prize);
        initBar();
        unbinder = ButterKnife.bind(this);
        init();
    }

    private void init() {
        txtTitle.setText("我的奖品");
        MyPrizeAdapter adapter = new MyPrizeAdapter(getSupportFragmentManager());
        pager.setAdapter(adapter);

    }

    @OnClick({R.id.btn_back, R.id.btn_one, R.id.btn_two, R.id.btn_three})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.btn_back:
                finish();
                break;
            case R.id.btn_one:
                selectPage(0);
                break;
            case R.id.btn_two:
                selectPage(1);
                break;
            case R.id.btn_three:
                selectPage(2);
                break;
        }
    }

    private void selectPage(int poi) {
        initColor();
        switch (poi) {
            case 0:
                lineOne.setVisibility(View.VISIBLE);
                btnOne.setTextColor(0xff4C81FF);
                pager.setCurrentItem(poi);
                break;
            case 1:
                lineTwo.setVisibility(View.VISIBLE);
                btnTwo.setTextColor(0xff4C81FF);
                pager.setCurrentItem(poi);
                break;
            case 2:
                lineThree.setVisibility(View.VISIBLE);
                btnThree.setTextColor(0xff4C81FF);
                pager.setCurrentItem(poi);
                break;
        }
    }

    private void initColor() {
        btnOne.setTextColor(0xff616185);
        btnTwo.setTextColor(0xff616185);
        btnThree.setTextColor(0xff616185);
        lineOne.setVisibility(View.GONE);
        lineTwo.setVisibility(View.GONE);
        lineThree.setVisibility(View.GONE);
    }


    public class MyPrizeAdapter extends FragmentPagerAdapter {

//        String[] tabs = {"未还账单", "还款记录"};

        public MyPrizeAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public int getCount() {
            return 3;
        }

        @Override
        public Fragment getItem(int position) {
            MyPrizeFragment fragment = new MyPrizeFragment();
            Bundle bundle = new Bundle();
            bundle.putInt("type", (position + 1));
            fragment.setArguments(bundle);
            return fragment;
        }


    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        unbinder.unbind();
        unbinder = null;
    }
}
